#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

struct Edge {
    int x, y, w;

    bool operator<(const Edge &e) const {
        return w < e.w;
    }
} E[9] = {
        {1, 2, 1},
        {1, 3, 2},
        {2, 3, 6},
        {2, 4, 11},
        {3, 4, 9},
        {3, 5, 13},
        {4, 5, 7},
        {4, 6, 3},
        {5, 6, 4}

};

const int INF = 1 << 20;
int dis[7][7] = {{0,   INF, INF, INF, INF, INF, INF,},
                 {INF, 0,   1,   2,   INF, INF, INF,},
                 {INF, 1,   0,   6,   11,  INF, INF,},
                 {INF, 2,   6,   0,   9,   13,  INF,},
                 {INF, INF, 11,  9,   0,   7,   3,},
                 {INF, INF, INF, 13,  7,   0,   4,},
                 {INF, INF, INF, INF, 3,   4,   0,},
};
map<int, vector<int>> adj;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for (int i = 0; i <= 6; i++) {
        adj[i] = vector<int>();
        for (int j = 0; j <= 6; j++) {
            if ( i == j )dis[i][j] = 0;
            else dis[i][j] = INF;

        }
    }
    for (auto e:E) {
        dis[e.x][e.y] = dis[e.y][e.x] = e.w;
        adj[e.x].push_back(e.y);
        adj[e.y].push_back(e.x);
    }
    cout << "距离矩阵" << endl;
    for (int i = 0; i <= 6; i++) {
        for (int j = 0; j <= 6; j++) {
            if ( dis[i][j] == INF ) {
                cout << "INF";
            } else {
                cout << setw(3) << dis[i][j];
            }
            cout << " ";
        }
        cout << endl;
    }
    cout << "邻接表" << endl;
    for (int i = 1; i <= 6; i++) {
        cout << i << "={";
        for (auto v:adj[i]) {
            cout << v << ",";
        }
        cout << "}" << endl;
    }
    return 0;
}
